package Communicate;

/**
 * @author wuhan
 * @date 2019/9/21 21:47
 */


class StopThread implements Runnable{

    private boolean flag=true;
    @Override
    public   synchronized void  run() {
        while (flag){
            try {
                wait();
            }catch (InterruptedException e){

                System.out.println(Thread.currentThread().toString()+">>>>>Exception");
                flag=false;
            }
            System.out.println(Thread.currentThread().toString()+">>>>run");
        }
    }
    public void changeFlag(){
        flag =false;
    }
}
public class StopThreadDemo {
    public static void main(String[] args) {
        StopThread stopThread=new StopThread();
        Thread t0=new Thread(stopThread);
        Thread t1=new Thread(stopThread);
        t0.setPriority(Thread.MAX_PRIORITY);
//        t0.setDaemon(true);t1.setDaemon(true);
        t0.start();t1.start();
        int num=0;
        while (true){
            if (num++==60){
            //    stopThread.changeFlag();
                t1.interrupt();
                t0.interrupt();
                break;
            }
            System.out.println(Thread.currentThread().toString()+">>>>>"+num);
        }
        System.out.println("over");
    }
}
